<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var searchRange = function (nums, target) {
            let left = 0;
            if (nums.length == 0) {
                return ([-1, -1]);
            }

            let right = nums.length - 1;
            let res = [];
            while (left < right) {
                let middle = parseInt(left + (right - left) / 2);
                // 找左边界 
                if (nums[middle] < target) {
                    left = middle + 1;
                } else {
                    right = middle;
                }
            }
            if (nums[left] == target) {
                res[0] = left;
            } else {
                return ([-1, -1]);
            }

            right = nums.length - 1;

            while (left < right) {
                let middle = parseInt(left + (right - left + 1) / 2);
                // 找右边界
                if (nums[middle] > target) {
                    right = middle - 1;
                } else {
                    left = middle;
                }
            }
            if (nums[right] == target) {
                res[1] = right;
                return res;
            }
        };

        console.log(searchRange([1, 3], 1));
    </script>
</head>

<body>

</body>

</html>